{% extends 'base.html.twig' %}

{% block title 'Edit Package' %}

{% block alt_title 'Edit an existing package' %}

{% block content %}
<form action="{{ path('manage_package_update', { id: package.id }) }}" method="post">
<div class="row">
    <div class="col-xs-12 col-sm-8 col-md-3">
        <div class="box box-success">
            <div class="box-header">
                <h3 class="box-title">Package Information</h3>
            </div>

            <div class="box-body">
                <div class="form-group">
                    <label for="name">Name</label>
                    <input type="text" name="name" value="{{ package.name }}" placeholder="Enter name" id="name" class="form-control" required>
                </div>
                <div class="form-group">
                    <label for="description">Description</label>
                    <textarea name="description" placeholder="Enter description" id="description" class="form-control">{{ package.description }}</textarea>
                </div>
                <div class="form-group">
                    <label for="enabled">
                        <input type="checkbox" name="enabled" value="1" {% if package.enabled %}checked="checked" {% endif %}id="enabled"> &nbsp; Enabled
                    </label>
                </div>
                <div class="form-group">
                    <label for="fqn">Fully-qualified Name</label>
                    <input type="text" name="fqn" value="{{ package.fqn }}" id="fqn" class="form-control" disabled>
                </div>
                <div class="form-group">
                    <label for="configuration_id">Remote Repository</label>
                    <select class="form-control" name="configuration_id" id="configuration_id" disabled>
                        <option value="">Select remote</option>
                      {% for config in remotes %}
                        <option value="{{ config.id }}"{% if package.remote is sameas(config) %} selected="selected"{% endif %}>{{ config.name }}</option>
                      {% endfor %}
                    </select>
                </div>
            </div>

            <div class="box-footer">
                <button class="btn btn-primary" type="submit">Update Package</button>
            </div>

        </div>
    </div>
    <div class="col-xs-12 col-sm-8 col-md-3 plugin-box"{% if not package.enabled %} style="display: none"{% endif %}>
    {% for controller in plugin_controllers(constant('Terramar\\Packages\\Plugin\\Actions::PACKAGE_EDIT'), { id: package.id }) %}
        {{ render(controller) }}
        {% if loop.index % 2 == 0 %}
    </div>
    <div class="col-xs-12 col-sm-8 col-md-3 plugin-box"{% if not package.enabled %} style="display: none"{% endif %}>
        {% endif %}
    {% endfor %}
    </div>
</div>
</form>
{% endblock %}

{% block javascripts %}
<script type="text/javascript">
  $(function() {
    var $plugins = $('.plugin-box');
    $(document.getElementById('enabled')).change(function() {
      if ($(this).is(':checked')) {
        $plugins.fadeIn('fast');
      } else {
        $plugins.fadeOut('fast');
      }
    });
  })
</script>
{% endblock %}
